import Request from '../lib/luch-request/index.js'

const request = new Request()

// 请求配置
request.setConfig( (config) => {
	config.baseURL = 'http://36.134.80.177:8201'
	config.header = {
		'Content-Type': 'application/json',
	}
	return config
})

// 请求拦截 
request.interceptors.request.use((config) => {
	const token = uni.getStorageSync('token') || ''
	console.log(token)
	config.header = {
	    ...config.header,
	    'Authorization': token
	  }
	  console.log(config)
	return config
})

// 响应拦截
request.interceptors.response.use((config) => {
	console.log(config)
	if (config.data.code != 200) {
		console.log(2)
		uni.showToast({
			icon: 'none',
			title: config.data.message
		})
		
		return config
	}
	return config
}, error => {
	uni.showToast({
		icon: 'none',
		title: error.data.message
	})
})


export default request